package cn.edu.jxau.test;

import java.util.Arrays;
import java.util.Objects;

public class Main {

	public static void main(String[] args) {

		char[] str = "abcedfg".toCharArray();
		foo(str, 2);
		System.out.println(Arrays.toString(str));
	}

	public static void foo(char[] str, int index) {

		Objects.requireNonNull(str, "参数str不能为null");
		reverse(str, 0, index);
		reverse(str, index, str.length);
		reverse(str, 0, str.length);
	}

	public static void reverse(char[] str, int start, int end) {

		int low = start;
		int high = end - 1;
		while (low < high) {
			char temp = str[low];
			str[low] = str[high];
			str[high] = temp;
			low++;
			high--;
		}
	}
}